package com.hbsx;

import com.hbsx.filters.post.PostFilter;
import com.hbsx.filters.pre.FirstPreFilter;
import com.hbsx.filters.pre.SecondPreFilter;
import com.hbsx.filters.pre.ThirdPreFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
@EnableOAuth2Sso
public class ZuulApplication extends WebSecurityConfigurerAdapter {

    public static void main(String[] args) {

        SpringApplication.run(ZuulApplication.class,args);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers("/login","/rry-pay/**")
                .permitAll()
                .anyRequest()
                .authenticated()
                .and()
                .csrf()
                .disable();
    }

    /**
     * 注入自定义filter
     * @return
     */
    @Bean
    public FirstPreFilter firstPreFilter(){

        return new FirstPreFilter();
    }

    @Bean
    public SecondPreFilter secondPreFilter(){

        return new SecondPreFilter();
    }

    @Bean
    public ThirdPreFilter thirdPreFilter(){

        return new ThirdPreFilter();
    }

    @Bean
    public PostFilter postFilter(){

        return new PostFilter();
    }
}
